<template>
	<view class="home">
		<view v-if="loginDialog==false">
		<search :showDownload="true" :download-data="data.install"></search>
		<!-- #ifdef APP-PLUS -->
		<u-swiper @click="handleSlide" :list="data.slide" keyName="ad_code" previousMargin="20" nextMargin="20" circular
			:autoplay="true" radius="15" height="480"  bgColor="#ffffff"></u-swiper>
		<!-- #endif -->
		<!-- #ifdef H5 -->
		<u-swiper @click="handleSlide" :list="data.slide" keyName="ad_code" previousMargin="20" nextMargin="20" circular
			:autoplay="true" radius="15" height="430"  bgColor="#ffffff"></u-swiper>
		<!-- #endif -->
		</view>
		<pageBottom></pageBottom>
		<!-- #ifdef APP-PLUS -->
		<app-update ref="app_update" :force="false" :tabbar="true"></app-update>
		<!-- #endif -->
		
		<!-- 登录弹窗 -->
		<u-popup :show="loginDialog" mode="center" >
			<loginindex @close="loginDialog=false"></loginindex>
		</u-popup>
	</view>
	
</template>

<script>
	import loginindex from '@/components/loginindex.vue';
	import search from '@/components/search.vue';
	import pageBottom from '@/components/pageBottom.vue';
	import navSwiper from '@/components/navSwiper.vue'
	export default {
		components: {
			loginindex,
			search,
			pageBottom
		},
		data() {
			return {
				loginDialog: false,
				data: {
				},
				keyword: '',
				bannerHeight:'',
			};
		},
		onLoad() {
			for (var i = 0; i < 5; i++) {
				uni.setTabBarItem({
					index: i,
					text: this.$t(`tab.menu${i + 1}`),
				})
			}
		},
		onShow() {
			
			uni.setNavigationBarTitle({
				title: this.$t('tab.menu3'),
			})
			this.init()
			if (!this.$user.isLogin()) {
				this.loginDialog = true
				return
			}
		},
		mounted() {
			// #ifdef APP-PLUS
			this.$refs.app_update.update(); //调用子组件 检查更新
			// #endif
		},
		
		methods: {
			async init() {
				const result = await this.$api('/index/index')
				console.log('result', result)
				this.data = result

			},
			
			handleSlide(e) {
				const item = this.data.slide[e]
				this.slideClick(item)
			},
			
			slideClick(item) {
				// 商品
				if (item.media_type == 3) {
					uni.navigateTo({
						url: '/pages/goodDetail?id=' + item.ad_link
					})
				}
				// 分类
				if (item.media_type == 4) {
					uni.navigateTo({
						url: '/pages/shopList?cid=' + item.ad_link
					})
				}
				// 链接
				if (item.media_type == 5) {
					uni.navigateTo({
						url: '/pages/webview?weburl=' + encodeURIComponent(item.ad_link)
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.home {
		padding-bottom: 50px;
	}

	.discount {
		.discountList {
			.discount_one {
				box-shadow: none;
			}
		}

		.titles {
			margin-bottom: 12px;
			width: 100%;
			padding: 12px 12px 0;
			box-sizing: border-box;

			.all {
				font-size: 12px;
				color: #909399;
			}

			.showCutDown {
				width: max-content;
				background: $main;
				padding: 6px 20px;
				border-radius: 0px 0px 5px 5px;
				position: relative;
				top: -12px;

				::v-deep.u-count-down__text {
					color: white !important;
				}
			}

			.showTit {
				font-weight: bold;
				font-size: 15px;
			}
		}

		background: #fefaac;
	}

	.swiper {
		display: flex;
		flex-wrap: wrap;
		height: 200px;

		.swiper-item {
			width: 25vw;
		}
	}

	.discountList {
		width: 100%;
		padding: 0 12px;
		box-sizing: border-box;

		.discount_one {
			width: 48%;
			// width: 168px;
			margin-bottom: 15px;
			overflow: hidden;
			background: white;
			border-radius: 3px;
			box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.1);

			.shopInfo {
				.shopPrice {
					width: 100%;

					.newPrice {
						font-weight: bold;
						font-size: 16px;
					}

					.oldPrice {
						text-decoration: line-through;
						margin-right: 10px;
					}
				}

				.shopName {
					width: 100%;
					overflow: hidden;
					white-space: pre-wrap;
					word-wrap: break-word;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					margin-bottom: 5px;
				}

				width:100%;
				padding:10px;
				box-sizing: border-box;
				// background:#ececec;
			}

			.shopImg {
				width: 100%;
				height: 100%;
				background: white;
				position: relative;
			}
		}
	}

	.classify1 {
		width: 100%;
		margin-top: 12px;

		.kind_title {
			width: 100%;
			padding: 0 12px;
			box-sizing: border-box;
			// color:#404553;
			//color: $main;
			font-weight: bold;
			margin-bottom: 10px;
		}

		swiper-item {
			.kindDesc {
				.kind_desc2 {
					font-size: 10px;
					margin-top: 3px;
				}

				width: 100%;
				padding: 5px;
				box-sizing: border-box;
				font-size: 12px;
			}

			display: inline-block;
			width: max-content;
			padding:0 5px;
			text-align: left;
			box-sizing:border-box;
		}

		.kind_list {
			.shopOne {
				.shopInfo {
					width: 100%;
					padding: 5px;
					box-sizing: border-box;

					.shopPrice {
						font-size: 12px;

						.oldPrice {
							margin-left: 12px;
							color: #7e8598;
							font-size: 10px;
							text-decoration: line-through;
						}
					}

					.shopName {
						font-size: 14px;
						width: 128px;
						overflow: hidden;
						white-space: pre-wrap;
						word-wrap: break-word;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						margin-bottom: 5px;
					}
				}

				.shopImg {
					width: 100%;
					position: relative;
				}

				width: 140px;
				padding: 0 6px;
				margin-right: 10px;
				box-sizing: border-box;
				display:inline-block;
			}

			width:100%;
			padding:0 12px;
			font-size: 16px;
			box-sizing: border-box;
			white-space: nowrap;
			overflow: hidden;
			margin-bottom: 10px;
			overflow-x: auto;

		}

		.kind_list::-webkit-scrollbar {
			height: 0;
		}
	}

	.kind {
		swiper-item {
			display: inline-block;
			width: max-content;
			padding: 0 5px;
			text-align: center;
			box-sizing: border-box;
		}

		.kindOne {
			.kindIcon {
				width: 64.5px;
				height: 64.5px;
				border-radius: 50%;
				margin: 0 auto 5px;
			}

			width:64.5px;
			display: inline-block;
			font-size:12px;
			margin-bottom: 10px;
		}

		width:calc(100% - 24px);
		margin:0 auto;
		overflow: hidden;
		overflow-x:auto;
	}

	.tools {
		width: calc(100% - 24px);
		position: absolute;
		right: 12px;
		bottom: 12px;

		.carIcon {
			width: 24px;
			height: 24px;
			padding: 2px;
			box-sizing: border-box;
			background: white;
			border-radius: 4px;
			text-align: center;
			line-height: 20px;
			box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.1);
		}
	}

	.time {
		@include flex;
		align-items: center;

		&__custom {
			margin-top: 4px;
			width: 22px;
			height: 22px;
			background-color: $main;
			border-radius: 4px;
			/* #ifndef APP-NVUE */
			display: flex;
			/* #endif */
			justify-content: center;
			align-items: center;

			&__item {
				color: #fff;
				font-size: 12px;
				text-align: center;
			}
		}

		&__doc {
			color: $u-primary;
			padding: 0px 4px;
		}

		&__item {
			color: #606266;
			font-size: 15px;
			margin-right: 4px;
		}
	}

	.adv {
		width: calc(100% - 32px);
		margin: 12px auto;
	}

	.adv2 {
		width: calc(100% - 50px);
	}

	page {
		background: white;
	}




	.cate-nav-swiper {
		
	}

	.cate-nav {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
	}

	.cate-nav-image {
		width: 80.5px	;
		height: 80.5px;
		border-radius: 50%;
	}

	.cate-nav-title {
		font-size: 12px;
		color: $uni-text-color-grey;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
	}
	.u-grid{
		align-items: flex-start;
	}
	.address-box {
		display: flex;
		align-items: center;
		padding: 0 0 25rpx 20rpx;
	}
	::v-deep.u-swiper__wrapper__item__wrapper__image div{background-size:100%!important}
</style>